package com.fhz.mvvmshopjava.utils;

import com.fhz.mvvmshopjava.api.ServiceApi;
import com.fhz.utilsfhz.LiveDataCallAdapterFactory;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * 时间:2022/5/23
 *
 * @author msfeng
 * 简述: TODO
 */
public class RetrofitManger {

    private RetrofitManger(){}

    private static RetrofitManger retrofitManger = new RetrofitManger();

    public synchronized static RetrofitManger getInstance(){
        return retrofitManger;
    }

    private Retrofit retrofit; //执行一次
    public Retrofit getRetrofit(){
        if(retrofit == null){
            retrofit = new Retrofit.Builder()
                    .baseUrl(ServiceApi.BASE_URL)
                    .client(new OkHttpClient().newBuilder()
                            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                            .build())
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(new LiveDataCallAdapterFactory())
                    .build();
        }
        return retrofit;
    }




}

